# -*- coding: utf-8 -*-



import  wx
import  os
import sys
import about

#import message as msg
from features.UI.common import windict
import time
from generator import ideagen
from generator import mapgen


class ActionMenu:
    
    class __ActionMenu:   
    
    
        def __init__(self,app):
            self.wd = windict.WinDict()
            self.app = app
            self.frame = app.myframe
            pass
        
        def OnExitApp(self, evt):
            self.frame.Close(True)
    
        def OnGen(self,event):
            #print "on gen"
            ideagen.main()

        def OnMapGen(self,event):
            #print "on gen"
            mapgen.main()


        def OnDoit(self,evt):
            #self.win.Begin()
            file = wx.FileSelector(u"选择文件", default_path="", 
                                   default_filename="",default_extension="", 
                                   wildcard="*.*", flags=0, parent=self.app.myframe,x=-1, y=-1)
            print "do it"
            #evt.Skip()
        
        
        def OnHelp(self,evt):
            helpfile ="vpipe.chm"
            try:
                os.startfile(helpfile)  # for windows ?
            except:
                msg.Msg("coult not find the help file")
                
            #evt.Skip()
            
        def OnAbout(self,event):
            dialog = about.About(self.app.myframe)
            dialog.ShowModal()
            dialog.Destroy()
            #event.Skip()
    
        def OnConsole(self,event):
            
            #print "console %s" %( time.time() )
            try:
                id = self.wd.get("CONSOLE")
            
                #print id
                textctrl = wx.FindWindowById(id)
                text = u" %s console  一些信息而已" %(time.time())
                textctrl.AppendText(text+"\n")        
            except:
                print "could not find console window"
            # todo aui
            #event.Skip()
        
        def OnLog(self,event):
            mgr = self.app.getMgr()
            #print mgr.SavePerspective()
            #print "log %s" %( time.time() )
            try:
                id = self.wd.get("LOG")
                #print id
                textctrl = wx.FindWindowById(id)
                text = u"some information  一些信息而已"
                textctrl.AppendText(text+"\n")        
            except:
                print "could not find log window"
            # todo: aui
            #event.Skip()
    
        def OnNavigator(self,event):
            
            mgr = self.app.getMgr()
            mgr.GetPane(self.app.p1).Hide()
            mgr.GetPane(self.app.p1).Show()
            
            # canuse: let the pane float
            #mgr.GetPane(self.app.p1).Float()
            
            mgr.Update()
            print "on nav"        

        def OnLoadPerspective(self,event):
            mgr = self.app.getMgr()
            #mgr.CreateFloatingFrame(self.app.p2, pos=(50,50))
            #mgr.AddPane(self.app.p2, wx.BOTTOM, "Output")     
            """
            all = mgr.GetAllPanes()
            for one in all:
                print one       
            #mgr.RestorePane(self.app.p2)
            """
            mgr.LoadPerspective(self.app.str)           

            mgr.Update()
            print "on load"            
                        
        def OnOutput(self,event):
            
            mgr = self.app.getMgr()
            #mgr.CreateFloatingFrame(self.app.p2, pos=(50,50))
            #mgr.AddPane(self.app.p2, wx.BOTTOM, "Output")     
            """
            all = mgr.GetAllPanes()
            for one in all:
                print one       
            #mgr.RestorePane(self.app.p2)
            """
            #mgr.LoadPerspective(self.app.str)
            
            mgr = self.app.getMgr()
            mgr.GetPane(self.app.p2).Hide()
            mgr.GetPane(self.app.p2).Show()
            #mgr.AddPane(self.app.p1, wx.LEFT, "Nav")
            mgr.Update()
            print "on output"            
            
        def OnQuery(self,evt):
            #self.win.Begin()
            #fr = IncomeFrame(self)
            #fr.Show()
            
            frame = wx.Frame(None, -1, u"工资数据", pos=(50,50), size=(800,800),
                style=wx.DEFAULT_FRAME_STYLE)
    
            
            page1 = income.IncomeInfo(frame)
            frame.Show()
            evt.Skip()
        
    instance = None

    def __init__(self,app):
        if not ActionMenu.instance:
            ActionMenu.instance =ActionMenu.__ActionMenu(app)            
        else:
            pass
    #print Log.instance

    def __getattr__(self, name):
        return getattr(self.instance, name)         
